package com.game.forestfire.core;

import com.game.forestfire.core.events.EventBus;

import java.util.HashMap;
import java.util.Map;

/**
 * 模块之间的桥梁
 * 注册服务，获取服务
 * 提供事件总线
 */
public class GameContext {
    //定义事件总线
    private final EventBus eventBus = new EventBus();
    //定义服务Hash集合
    private final Map<Class<?>, Object> services = new HashMap<>();
    //返回事件总线对象
    public EventBus getEventBus() {
        return eventBus;
    }
    //服务注册
    public <T> void registerService(Class<T> type, T service) {
        services.put(type, service);
    }
    //获取服务
    public <T> T getService(Class<T> type) {
        return type.cast(services.get(type));
    }

}



